/*
    Copyright (C) 2009  Twinator S.A.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package com.twnavigator.service
{
	import mx.controls.Alert;
	import mx.rpc.AsyncToken;
	import mx.rpc.http.HTTPService;
	
	import com.twnavigator.model.TwItem;
	
	import mx.managers.CursorManager;

	public class TwService
	{
		private static const rootDomain: String = "http://www.twinator.com/";
		private static const rootPage: String = "index.php?option=com_twnserver&view=default&Itemid=17&";		
		
		public function TwService()
		{
		}		
	
		public static function getItemInfo(twScreenName: String, client: TwItem): void {
			try {			
				var service: HTTPService = new HTTPService();
				service.resultFormat="e4x";
				
				var serviceUrl: String;				 
				serviceUrl = TwService.rootDomain + TwService.rootPage + "&task=showUser&screen_name=" + twScreenName;			
				service.url = serviceUrl;			
				service.addEventListener("result", client.getItemInfoResult);
				service.addEventListener("fault", client.getItemInfoFault);

				CursorManager.setBusyCursor();

				service.send();
				
				//Alert.show("getItemInfo "+serviceUrl);
			} catch (erObject:Error) {
				CursorManager.removeBusyCursor();

				Alert.show("getItemInfo Exception "+erObject.toString());
			}
		}		
		
		public static function getItemInfoFriendsList(twScreenName: String, client: Object): void {
			try {			
				var service: HTTPService = new HTTPService();
				service.resultFormat="e4x";

				var serviceUrl: String;				 
				serviceUrl = TwService.rootDomain + TwService.rootPage + "&task=getFriends&screen_name=" + twScreenName;			
				service.url = serviceUrl;			
				
				service.addEventListener("result", client.getItemInfoResultFriendsList);
				service.addEventListener("fault", client.getItemInfoFault);				

				service.send();
				
				//Alert.show("getItemInfoFriendsList "+serviceUrl);
			} catch (erObject:Error) {
				Alert.show("getItemInfoFriendsList Exception "+erObject.toString());
			}				
		}
		
		public static function getPermissions(twScreenName: String, client: Object): void {
			try {			
				var service: HTTPService = new HTTPService();
				service.resultFormat="e4x";

				var serviceUrl: String;				 
				serviceUrl = TwService.rootDomain + TwService.rootPage + "&task=getPermissions&screen_name=" + twScreenName;			
				service.url = serviceUrl;			
				
				service.addEventListener("result", client.getPermissions);
				service.addEventListener("fault", client.getFault);				

				service.send();
				
				//Alert.show("getItemInfoFriendsList "+serviceUrl);
			} catch (erObject:Error) {
				Alert.show("getPermissions Exception "+erObject.toString());
			}				
		}		
	}
}
			//Alert.show("service.url " + service.url);
			
			//Alert.show("service.url " + service.url);		
/*				
		public static function getDetailPageUrlScreenName(id: String): String {
			return "TwitterNavigatorProxy.php?type=show&screen_name=" + id;
		}
		
		public static function getDetailPageUrlUserId(id: String): String {
			return "TwitterNavigatorProxy.php?type=show&user_id=" + id;
		}
*/		
